﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.Text;
using AgileNYCWebService.Manager.Data;
using AgileNYCWebService.Manager.Data.Table;

namespace AgileNYCWebService
{
	// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "AgileSync" in code, svc and config file together.
	// NOTE: In order to launch WCF Test Client for testing this service, please select AgileSync.svc or AgileSync.svc.cs at the Solution Explorer and start debugging.

	[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
	public class AgileSync : IAgileSync
	{
		public JsonResult Contacts(SyncClass syncData)
		{
			try
			{
				DateTime dateTime = DateTime.Parse(syncData.ModifiedDate);
				return new DataManager(syncData.UserToken).ContactsSync(dateTime);
			}
			catch (Exception ex)
			{
				return new JsonResult() { Error = "Invalid DateTime", Result = "" };
			}
		}

		public JsonResult Events(SyncClass syncData)
		{
			try
			{
				DateTime dateTime = DateTime.Parse(syncData.ModifiedDate);
				return new DataManager(syncData.UserToken).EventsSync(dateTime);
			}
			catch (Exception ex)
			{
				return new JsonResult() { Error = "Invalid DateTime", Result = "" };
			}
		}

		public JsonResult Participants(SyncClass syncData)
		{
			try
			{
				DateTime dateTime = DateTime.Parse(syncData.ModifiedDate);
				return new DataManager(syncData.UserToken).ParticipantsSync(dateTime);
			}
			catch (Exception ex)
			{
				return new JsonResult() { Error = "Invalid DateTime", Result = "" };
			}
		}

		public JsonResult Ratings(SyncClass syncData)
		{
			try
			{
				DateTime dateTime = DateTime.Parse(syncData.ModifiedDate);
				return new DataManager(syncData.UserToken).RatingsSync(dateTime);
			}
			catch (Exception ex)
			{
				return new JsonResult() { Error = "Invalid DateTime", Result = "" };
			}
		}

		public JsonResult Users(SyncClass syncData)
		{
			try
			{
				DateTime dateTime = DateTime.Parse(syncData.ModifiedDate);
				return new DataManager(syncData.UserToken).UsersSync(dateTime);
			}
			catch (Exception ex)
			{
				return new JsonResult() { Error = "Invalid DateTime", Result = "" };
			}
		}
	}
}
